﻿using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Library.WebControls.SimpleGridView {
	[PersistenceMode(PersistenceMode.InnerProperty)]
	[Bindable(false)]
	[ToolboxItem(false)]
	[PersistChildren(false)]
	[ParseChildren(true)]
	public class SpGvColumnCollection : IList<SpGvBaseColumn>, IList {
		protected List<SpGvBaseColumn> InnerList = new List<SpGvBaseColumn>();
		internal Style ParrentStyle { get; set; }
		public SpGvBaseColumn Find(string columnName) {
			return this.FirstOrDefault(col => col.Name == columnName);
		}


		#region IList Members


		public virtual void Add(SpGvBaseColumn item) {
			InnerList.Add(item);
		}

		public virtual void Clear() {
			InnerList.Clear();
		}

		public virtual bool Contains(SpGvBaseColumn item) {
			return InnerList.Contains(item);
		}

		public void CopyTo(SpGvBaseColumn[] array, int arrayIndex) {
			InnerList.CopyTo(array, arrayIndex);
		}

		public virtual bool Remove(SpGvBaseColumn item) {
			return InnerList.Remove(item);
		}

		public int Count {
			get { return InnerList.Count; }
		}

		public bool IsReadOnly {
			get { return false; }
		}

		int IList.Add(object value) {
			//Add((SpGvColumn)value);
			//return Count;
			return ((IList)InnerList).Add(value);
		}


		void IList.Clear() {
			Clear();

		}

		bool IList.Contains(object value) {
			return ((IList) InnerList).Contains(value);
		}

		int IList.IndexOf(object value) {
			return ((IList) InnerList).IndexOf(value);
		}

		void IList.Insert(int index, object value) {
			((IList) InnerList).Insert(index, value);
		}

		bool IList.IsFixedSize {
			get { return false; }
		}

		bool IList.IsReadOnly {
			get { return false; }
		}

		void IList.Remove(object value) {
			((IList) InnerList).Remove(value);
		}

		public int IndexOf(SpGvBaseColumn item) {
			return InnerList.IndexOf(item);
		}

		public virtual void Insert(int index, SpGvBaseColumn item) {
			InnerList.Insert(index, item);
		}

		public virtual void RemoveAt(int index) {
			InnerList.RemoveAt(index);
		}

		public SpGvBaseColumn this[int index] {
			get { return InnerList[index]; }
			set { InnerList[index] = value; }
		}

		void IList.RemoveAt(int index) {
			RemoveAt(index);
		}

		object IList.this[int index] {
			get { return this[index]; }
			set { this[index] = (SpGvBaseColumn)value; }
		}

		#endregion

		#region ICollection Members

		void ICollection.CopyTo(System.Array array, int index) {
			((IList) InnerList).CopyTo(array, index);
		}

		int ICollection.Count {
			get { return Count; }
		}

		bool ICollection.IsSynchronized {
			get { return ((ICollection)InnerList).IsSynchronized; }
		}

		object ICollection.SyncRoot {
			get { return ((ICollection)InnerList).SyncRoot; }
		}

		#endregion

		#region IEnumerable Members

		//protected override void SetDirtyObject(object o) {
		//  //throw new NotImplementedException();
		//}
		//protected override object CreateKnownType(int index) {
		//  switch (index) {
		//    case 0:
		//      return new SpGvColumn();
		//    case 1:
		//      return new SpGvComboxColumn();
		//    case 2:
		//      return new SpGvDateColumn();
		//    case 3:
		//      return new SpGvExComboxColumn();
		//    case 4:
		//      return new SpGvSpinColumn();
		//  }
		//  return base.CreateKnownType(index);
		//}

		public IEnumerator<SpGvBaseColumn> GetEnumerator() {
			return InnerList.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}

		#endregion
	}
}
